using WCSFContrib.PageFlow.Xml;
using WCSFContrib.PageFlow;
using System.Collections;

namespace XmlPageFlowWithShoppingCartQuickstart.Store.PageFlows
{
    public class StoreXmlPageFlow : IXmlPageFlowConditionEvaluator
	{
        public void OnEvaluateCondition(ConditionalEventArgs e)
        {
            switch (e.Condition)
            {
                case "AllowCheckout":
                    e.ViewName = AllowCheckout(e.UserDataStore);
                    break;
            }
        }


        private string AllowCheckout(PageFlowState state)
        {
           if (state.Contains("Cart"))
            {
                if (((IList)state["Cart"]).Count < 1)
                {
                    return "Error";
                }
            }

            return "Checkout";
        }
    }
}
